package com.xxxx.server.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxxx.server.mapper.PositionMapper;
import com.xxxx.server.pojo.Position;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.service.IPositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhoubin
 */
@Service
public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> implements IPositionService {
    @Autowired
    private PositionMapper positionMapper;

    /**
     * 查询所有的职位信息
     * @return
     */
    @Override
    public List<Position> selectAllPosition() {
        return positionMapper.selectAllPosition();
    }

    /**
     * 添加职位
     * @param position
     * @return
     */
    @Override
    public RespBean addPosition(Position position) {
        return check(positionMapper.addPosition(position));
    }

    /**
     * 批量删除职位
     * @param ids
     * @return
     */
    @Override
    public RespBean deletePositions(List<Integer> ids) {
        return check(positionMapper.deletePositions(ids));
    }

    /**
     * 删除职位
     * @param id
     * @return
     */
    @Override
    public RespBean deletePosition(Integer id) {
        return check(positionMapper.deletePosition(id));
    }

    /**
     * 修改职位信息
     * @param position
     * @return
     */
    @Override
    public RespBean updatePositionInfo(Position position) {
        return check(positionMapper.updatePositionInfo(position));
    }

    /**
     * 封装 操作成功或者失败
     * @param rows 影响行数
     * @return
     */
    private RespBean check(Integer rows){

        if (rows > 0){
            return RespBean.success("操作成功");
        }
        return RespBean.error("操作失败");
    }
}
